package razor.blade;

import javafx.beans.binding.*;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.beans.property.*;
import javafx.beans.value.*;
import javafx.scene.effect.*;
import tee.binding.*;

public class Plate {
    private Numeric x;
    private Numeric y;
    private Numeric width;
    private Numeric height;
    private It<Color> color;
    private Group root;
    private Polygon flare;
    private Task adjustFlare;
    public Node node() {
        return root;
    }
    public Plate x(double it) {
        x.value(it);
        return this;
    }
    public Plate x(int it) {
        x.value(it);
        return this;
    }
    public Numeric x() {
        return x;
    }
    public Plate x(It<Double> it) {
        x.bind(it);
        return this;
    }
    public Plate y(double it) {
        y.value(it);
        return this;
    }
    public Plate y(int it) {
        y.value(it);
        return this;
    }
    public Numeric y() {
        return y;
    }
    public Plate y(It<Double> it) {
        y.bind(it);
        return this;
    }
    public Plate width(double it) {
        width.value(it);
        return this;
    }
    public Plate width(int it) {
        width.value(it);
        return this;
    }
    public Numeric width() {
        return width;
    }
    public Plate width(It<Double> it) {
        width.bind(it);
        return this;
    }
    public Plate height(double it) {
        height.value(it);
        return this;
    }
    public Plate height(int it) {
        height.value(it);
        return this;
    }
    public Numeric height() {
        return height;
    }
    public Plate height(It<Double> it) {
        height.bind(it);
        return this;
    }
    public Plate color(Color it) {
        color.value(it);
        return this;
    }
    public Plate color(It<Color> it) {
        color.bind(it);
        return this;
    }
    public Plate() {
        adjustFlare = new Task() {
            @Override public void doTask() {
                if (width != null) {
                    if (height != null) {
                        flare.getPoints().setAll(new Double[]{
                                    0.0d, 0.0d, width.value() / 3, 0.0d, width.value() / 6, height.value(), 0.0d, height.value()});
                    }
                }
            }
        };
        x = new Numeric().value(0);
        y = new Numeric().value(0);
        width = new Numeric().value(300).afterChange(adjustFlare);
        height = new Numeric().value(200).afterChange(adjustFlare);
        color = new It<Color>().value(Color.web("#003366"));
        root = new Group();
        Rectangle shadow = new Rectangle();
        shadow.xProperty().bind(new Tee<Double>(x));
        shadow.yProperty().bind(new Tee<Double>(y));
        shadow.widthProperty().bind(new Tee<Double>(width));
        shadow.heightProperty().bind(new Tee<Double>(height));
        shadow.fillProperty().bind(new Tee<Color>(color));
        DropShadow ds = new DropShadow();
        ds.setOffsetY(0.0);
        ds.setOffsetX(0.0);
        ds.setRadius(16);
        ds.setColor(Color.web("#000000"));
        shadow.setEffect(ds);
        root.getChildren().add(shadow);
        Rectangle r2 = new Rectangle();
        r2.xProperty().bind(shadow.xProperty());
        r2.yProperty().bind(shadow.yProperty());
        r2.widthProperty().bind(shadow.widthProperty());
        r2.heightProperty().bind(shadow.heightProperty());
        Stop[] stops2 = new Stop[]{new Stop(0, Color.web("#ffffff")), new Stop(0.1, Color.web("#ffffff00")), new Stop(1, Color.web("#ffffff"))};
        LinearGradient fill2 = new LinearGradient(0, 0, 137, 137, false, CycleMethod.REPEAT, stops2);
        r2.setFill(fill2);
        r2.setOpacity(0.03);
        root.getChildren().add(r2);
        Rectangle r3 = new Rectangle();
        r3.xProperty().bind(shadow.xProperty());
        r3.yProperty().bind(shadow.yProperty());
        r3.widthProperty().bind(shadow.widthProperty());
        r3.heightProperty().bind(shadow.heightProperty());
        Stop[] stops3 = new Stop[]{new Stop(0, Color.web("#ffffff")), new Stop(0.1, Color.web("#ffffff00")), new Stop(1, Color.web("#ffffff"))};
        LinearGradient fill3 = new LinearGradient(0, 0, 73, 73, false, CycleMethod.REPEAT, stops3);
        r3.setFill(fill3);
        r3.setOpacity(0.01);
        root.getChildren().add(r3);
        Rectangle r4 = new Rectangle();
        r4.xProperty().bind(shadow.xProperty());
        r4.yProperty().bind(shadow.yProperty());
        r4.widthProperty().bind(shadow.widthProperty());
        r4.heightProperty().bind(shadow.heightProperty());
        Stop[] stops4 = new Stop[]{new Stop(0, Color.web("#ffffff")), new Stop(0.1, Color.web("#ffffff00")), new Stop(1, Color.web("#ffffff"))};
        LinearGradient fill4 = new LinearGradient(0, 0, 307, 307, false, CycleMethod.REPEAT, stops4);
        r4.setFill(fill4);
        r4.setOpacity(0.05);
        root.getChildren().add(r4);
        Rectangle shine = new Rectangle();
        shine.xProperty().bind(shadow.xProperty());
        shine.yProperty().bind(shadow.yProperty());
        shine.widthProperty().bind(shadow.widthProperty());
        shine.heightProperty().bind(shadow.heightProperty());
        Stop[] shineStops = new Stop[]{new Stop(0, Color.web("#ffffff66")), new Stop(0.5, Color.web("#ffffff00"))};
        RadialGradient shineFill = new RadialGradient(0, 0, 0.5, 1, 2, true, CycleMethod.REPEAT, shineStops);
        shine.setFill(shineFill);
        root.getChildren().add(shine);
        flare = new Polygon();
        flare.translateXProperty().bind(shadow.xProperty());
        flare.translateYProperty().bind(shadow.yProperty());
        Stop[] flareStops = new Stop[]{new Stop(0, Color.web("#ffffff11")), new Stop(1, Color.web("#ffffff00"))};
        LinearGradient flareFill = new LinearGradient(0, 0, 0, 1, true, CycleMethod.REPEAT, flareStops);
        flare.setFill(flareFill);
        root.getChildren().add(flare);
        adjustFlare.start();
    }
}
